﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CentrifugalSealCalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            // populate global values based on user input
            double.TryParse(txtH0.Text, out Global.H0);
            double.TryParse(txtHbep.Text, out Global.Hbep);
            double.TryParse(txtQbep.Text, out Global.Qbep);

            // create impeller object 
            Impeller impeller = null;
            if (cboImpellerType.SelectedIndex == (int)EImpellerType.Closed)
            {
                impeller = new ImpellerClosed();
            }
            else
            {
                impeller = new ImpellerOpen();
            }

            // read impeller values
            double.TryParse(txtImpellerT.Text, out impeller.T);
            double.TryParse(txtImpellerC.Text, out impeller.C);

            double.TryParse(txtSpeedNs.Text, out impeller.Ns);
            double.TryParse(txtImpellerR1.Text, out impeller.R1);
            double.TryParse(txtImpellerR2.Text, out impeller.R2);
            double.TryParse(txtImpellerDs.Text, out impeller.Ds);

            double.TryParse(txtQ.Text, out impeller.Q);

            // read expeller value
            Expeller expeller = new Expeller();
            double.TryParse(txtExpellerT.Text, out expeller.T);
            double.TryParse(txtExpellerC.Text, out expeller.C);

            double.TryParse(txtSpeedNs.Text, out expeller.Ns);
            double.TryParse(txtExpellerR1.Text, out expeller.R1);
            double.TryParse(txtExpellerR2.Text, out expeller.R2);

            Calc calc = new Calc(impeller, expeller);
            double.TryParse(txtSuctionHead.Text, out calc.SuctionHead);
            double.TryParse(txtSpecificGravity.Text, out calc.SpecificGravity);
            Outputs outputs = calc.Start();

            txtAdvice.Text = outputs.Message;
            txtPmax1.Text = txtPmax.Text = (outputs.Pmax / 1000).ToString("0.00");
            txtPinlet1.Text = txtPinlet.Text = (outputs.Pinlet / 1000).ToString("0.00");
            txtSpeedNd.Text = outputs.Nd.ToString("0.00");
            txtImpellerR2new.Text = (outputs.dr * 1000).ToString("0.00");
            txtimpdr.Text = outputs.percReduction.ToString("0.00");

            txtMessageImpellerType.Text = outputs.MessageImepellerCode;
            gpImpellerPropertiesNew.Visible = !outputs.Safe;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cboImpellerType.Items.AddRange(Global.GetEnumDescriptions<EImpellerType>());
            cboImpellerType.SelectedIndex = (int)EImpellerType.Closed;

            UpdateLabels();
        }

        private void txtSpeed_TextChanged(object sender, EventArgs e)
        {
            UpdateLabels();
        }

        private void UpdateLabels()
        {
            ttApp.SetToolTip(lblSuctionHead, "Maximum inlet gauge pressure from expeller curve at " + txtSpeedNs.Text + " rpm.");
        }

        private void textPinlet_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtPmax_TextChanged(object sender, EventArgs e)
        {

        }

        private void label23_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtExpellerT_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
